/*
 * @lc app=leetcode.cn id=953 lang=javascript
 *
 * [953] 验证外星语词典
 */

// @lc code=start
/**
 * @param {string[]} words
 * @param {string} order
 * @return {boolean}
 */
var isAlienSorted = function(words, order) {
    let map=new Map()
    for(let i=0;i<order.length;i++){
        map.set(order[i],i)
    }
    for(let i=0;i<words.length-1;i++){
        let j=0
        while(j<words[i].length&&j<words[i+1].length){
            if(map.get(words[i][j])>map.get(words[i+1][j]))return false
            else if(map.get(words[i][j])<map.get(words[i+1][j])){
                break
            }else j++
            
        }
        if(j==words[i+1].length&&j<words[i].length)return false
    }
    return true
};
// @lc code=end

isAlienSorted(["word","world","row"],"worldabcefghijkmnpqstuvxyz")